package ${package.Controller};

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wang.cloud.common.core.api.ApiResult;
import ${package.Parent}.domain.co.${entity?replace('Entity', '')}AddCo;
import ${package.Parent}.domain.co.${entity?replace('Entity', '')}PageCo;
import ${package.Parent}.domain.co.${entity?replace('Entity', '')}UpdateCo;
import ${package.Parent}.domain.vo.${entity?replace('Entity', '')}PageVo;
import ${package.Parent}.domain.vo.${entity?replace('Entity', '')}Vo;
import ${package.Service}.${table.serviceName};
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * ${table.comment!} 前端控制器
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
@Tag(name = "${table.comment?replace("表","")}")
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("<#if package.ModuleName?? && package.ModuleName != "">/${package.ModuleName}</#if>/${controllerMappingHyphen?replace("-entity","")?replace("-","/")}")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} {
</#if>

    private final ${table.serviceName} service;

    @Operation(summary = "分页查询")
    @GetMapping("page")
    public ApiResult<IPage<${entity?replace('Entity', 'PageVo')}>> page(${entity?replace('Entity', 'PageCo')} pageCo) {
        return ApiResult.success(service.page(pageCo));
    }

    @Operation(summary = "获取详情")
    @GetMapping("info")
    public ApiResult<${entity?replace('Entity', 'Vo')}> page(@RequestParam Long id) {
        return ApiResult.success(service.getInfo(id));
    }

    @Operation(summary = "新增")
    @PostMapping("add")
    public ApiResult<Long> add(@Validated @RequestBody ${entity?replace('Entity', 'AddCo')} addCo) {
        Long id = service.add(addCo);
        return ApiResult.success(id);
    }

    @Operation(summary = "更新")
    @PostMapping("update")
    public ApiResult update(@Validated @RequestBody ${entity?replace('Entity', 'UpdateCo')} updateCo) {
        service.update(updateCo);
        return ApiResult.success();
    }

    @Operation(summary = "删除")
    @DeleteMapping("del")
    public ApiResult del(@RequestParam Long id) {
        service.del(id);
        return ApiResult.success();
    }
}
</#if>
